{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 人脸识别"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 面部检测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# A-1 面部检测\n",
    "import requests\n",
    "\n",
    "import json\n",
    "\n",
    "# set to your own subscription key value\n",
    "subscription_key = \"a87c46d16dd843819033d19fd3648e6d\"\n",
    "assert subscription_key\n",
    "\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://facelist.cognitiveservices.azure.com/face/v1.0/detect'\n",
    "\n",
    "# 请求正文body\n",
    "image_url ='http://m.qpic.cn/psc?/V13AubRD2hkvIo/TmEUgtj9EK6.7V8ajmQrENq3ipy5S68ar4*Wmwf3*OKobBiJOy*X6TtIXpPourUzi4GefQfg0TWVa7qbH0McHJsp3gOv0ZAqseyweWDOx9M!/b&bo=oAU4BKAFOAQBSW4!&rf=viewer_4'\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key}\n",
    "\n",
    "# 请求参数parameters\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 可选参数,请仔细阅读API文档\n",
    "    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "# json.dumps 将json--->bytes\n",
    "response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': 'dc37d557-8642-48cd-ac78-5d31fe83010c',\n",
       "  'faceRectangle': {'top': 331, 'left': 280, 'width': 66, 'height': 66},\n",
       "  'faceAttributes': {'smile': 0.026,\n",
       "   'headPose': {'pitch': 9.2, 'roll': 12.9, 'yaw': -16.3},\n",
       "   'gender': 'male',\n",
       "   'age': 50.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.008,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.002,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.026,\n",
       "    'neutral': 0.085,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.879},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.53},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.08},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.03,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 1.0},\n",
       "     {'color': 'brown', 'confidence': 0.83},\n",
       "     {'color': 'gray', 'confidence': 0.71},\n",
       "     {'color': 'other', 'confidence': 0.43},\n",
       "     {'color': 'red', 'confidence': 0.0},\n",
       "     {'color': 'blond', 'confidence': 0.0},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': '9fbd2a78-ebde-46e7-a2c6-1aae8a79b81c',\n",
       "  'faceRectangle': {'top': 229, 'left': 467, 'width': 60, 'height': 60},\n",
       "  'faceAttributes': {'smile': 0.0,\n",
       "   'headPose': {'pitch': 23.8, 'roll': 2.7, 'yaw': -2.8},\n",
       "   'gender': 'male',\n",
       "   'age': 45.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.001,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.01,\n",
       "    'happiness': 0.0,\n",
       "    'neutral': 0.572,\n",
       "    'sadness': 0.001,\n",
       "    'surprise': 0.416},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.61},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.0},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': False},\n",
       "   'accessories': [{'type': 'glasses', 'confidence': 0.74}],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.23,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 0.99},\n",
       "     {'color': 'brown', 'confidence': 0.82},\n",
       "     {'color': 'gray', 'confidence': 0.72},\n",
       "     {'color': 'other', 'confidence': 0.37},\n",
       "     {'color': 'blond', 'confidence': 0.04},\n",
       "     {'color': 'red', 'confidence': 0.03},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': 'd90016e1-2a66-4671-bd0e-63961c817e87',\n",
       "  'faceRectangle': {'top': 264, 'left': 873, 'width': 55, 'height': 55},\n",
       "  'faceAttributes': {'smile': 0.0,\n",
       "   'headPose': {'pitch': 17.1, 'roll': 0.2, 'yaw': 1.8},\n",
       "   'gender': 'male',\n",
       "   'age': 32.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'ReadingGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.0,\n",
       "    'neutral': 0.994,\n",
       "    'sadness': 0.006,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.48},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.0},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [{'type': 'glasses', 'confidence': 0.99},\n",
       "    {'type': 'headwear', 'confidence': 1.0}],\n",
       "   'occlusion': {'foreheadOccluded': True,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.0, 'invisible': True, 'hairColor': []}}},\n",
       " {'faceId': '91b0e4b8-1fda-45e9-9d60-fc3538844197',\n",
       "  'faceRectangle': {'top': 418, 'left': 621, 'width': 51, 'height': 51},\n",
       "  'faceAttributes': {'smile': 0.003,\n",
       "   'headPose': {'pitch': 6.2, 'roll': 1.4, 'yaw': -26.4},\n",
       "   'gender': 'male',\n",
       "   'age': 20.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.157,\n",
       "    'contempt': 0.022,\n",
       "    'disgust': 0.059,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.003,\n",
       "    'neutral': 0.756,\n",
       "    'sadness': 0.002,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.53},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.0},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.05,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'brown', 'confidence': 0.99},\n",
       "     {'color': 'black', 'confidence': 0.65},\n",
       "     {'color': 'red', 'confidence': 0.53},\n",
       "     {'color': 'other', 'confidence': 0.14},\n",
       "     {'color': 'gray', 'confidence': 0.11},\n",
       "     {'color': 'blond', 'confidence': 0.1},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': 'a239129d-6794-4c86-b592-d2e61b1aa947',\n",
       "  'faceRectangle': {'top': 249, 'left': 688, 'width': 50, 'height': 50},\n",
       "  'faceAttributes': {'smile': 0.977,\n",
       "   'headPose': {'pitch': 16.9, 'roll': -3.7, 'yaw': -6.0},\n",
       "   'gender': 'male',\n",
       "   'age': 23.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'ReadingGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.977,\n",
       "    'neutral': 0.023,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.53},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.0},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
       "   'accessories': [{'type': 'glasses', 'confidence': 0.98}],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.15,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'brown', 'confidence': 0.99},\n",
       "     {'color': 'black', 'confidence': 0.82},\n",
       "     {'color': 'red', 'confidence': 0.34},\n",
       "     {'color': 'gray', 'confidence': 0.27},\n",
       "     {'color': 'other', 'confidence': 0.18},\n",
       "     {'color': 'blond', 'confidence': 0.07},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}}]"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results = response.json()\n",
    "results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### josn转译"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': 'dc37d557-8642-48cd-ac78-5d31fe83010c',\n",
       "  'faceRectangle': {'top': 331, 'left': 280, 'width': 66, 'height': 66},\n",
       "  'faceAttributes': {'smile': 0.026,\n",
       "   'headPose': {'pitch': 9.2, 'roll': 12.9, 'yaw': -16.3},\n",
       "   'gender': 'male',\n",
       "   'age': 50.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.008,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.002,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.026,\n",
       "    'neutral': 0.085,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.879},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.53},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.08},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.03,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 1.0},\n",
       "     {'color': 'brown', 'confidence': 0.83},\n",
       "     {'color': 'gray', 'confidence': 0.71},\n",
       "     {'color': 'other', 'confidence': 0.43},\n",
       "     {'color': 'red', 'confidence': 0.0},\n",
       "     {'color': 'blond', 'confidence': 0.0},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': '9fbd2a78-ebde-46e7-a2c6-1aae8a79b81c',\n",
       "  'faceRectangle': {'top': 229, 'left': 467, 'width': 60, 'height': 60},\n",
       "  'faceAttributes': {'smile': 0.0,\n",
       "   'headPose': {'pitch': 23.8, 'roll': 2.7, 'yaw': -2.8},\n",
       "   'gender': 'male',\n",
       "   'age': 45.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.001,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.01,\n",
       "    'happiness': 0.0,\n",
       "    'neutral': 0.572,\n",
       "    'sadness': 0.001,\n",
       "    'surprise': 0.416},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.61},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.0},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': False},\n",
       "   'accessories': [{'type': 'glasses', 'confidence': 0.74}],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.23,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 0.99},\n",
       "     {'color': 'brown', 'confidence': 0.82},\n",
       "     {'color': 'gray', 'confidence': 0.72},\n",
       "     {'color': 'other', 'confidence': 0.37},\n",
       "     {'color': 'blond', 'confidence': 0.04},\n",
       "     {'color': 'red', 'confidence': 0.03},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': 'd90016e1-2a66-4671-bd0e-63961c817e87',\n",
       "  'faceRectangle': {'top': 264, 'left': 873, 'width': 55, 'height': 55},\n",
       "  'faceAttributes': {'smile': 0.0,\n",
       "   'headPose': {'pitch': 17.1, 'roll': 0.2, 'yaw': 1.8},\n",
       "   'gender': 'male',\n",
       "   'age': 32.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'ReadingGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.0,\n",
       "    'neutral': 0.994,\n",
       "    'sadness': 0.006,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.48},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.0},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [{'type': 'glasses', 'confidence': 0.99},\n",
       "    {'type': 'headwear', 'confidence': 1.0}],\n",
       "   'occlusion': {'foreheadOccluded': True,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.0, 'invisible': True, 'hairColor': []}}},\n",
       " {'faceId': '91b0e4b8-1fda-45e9-9d60-fc3538844197',\n",
       "  'faceRectangle': {'top': 418, 'left': 621, 'width': 51, 'height': 51},\n",
       "  'faceAttributes': {'smile': 0.003,\n",
       "   'headPose': {'pitch': 6.2, 'roll': 1.4, 'yaw': -26.4},\n",
       "   'gender': 'male',\n",
       "   'age': 20.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.157,\n",
       "    'contempt': 0.022,\n",
       "    'disgust': 0.059,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.003,\n",
       "    'neutral': 0.756,\n",
       "    'sadness': 0.002,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.53},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.0},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.05,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'brown', 'confidence': 0.99},\n",
       "     {'color': 'black', 'confidence': 0.65},\n",
       "     {'color': 'red', 'confidence': 0.53},\n",
       "     {'color': 'other', 'confidence': 0.14},\n",
       "     {'color': 'gray', 'confidence': 0.11},\n",
       "     {'color': 'blond', 'confidence': 0.1},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': 'a239129d-6794-4c86-b592-d2e61b1aa947',\n",
       "  'faceRectangle': {'top': 249, 'left': 688, 'width': 50, 'height': 50},\n",
       "  'faceAttributes': {'smile': 0.977,\n",
       "   'headPose': {'pitch': 16.9, 'roll': -3.7, 'yaw': -6.0},\n",
       "   'gender': 'male',\n",
       "   'age': 23.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'ReadingGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.977,\n",
       "    'neutral': 0.023,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.53},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.0},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
       "   'accessories': [{'type': 'glasses', 'confidence': 0.98}],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.15,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'brown', 'confidence': 0.99},\n",
       "     {'color': 'black', 'confidence': 0.82},\n",
       "     {'color': 'red', 'confidence': 0.34},\n",
       "     {'color': 'gray', 'confidence': 0.27},\n",
       "     {'color': 'other', 'confidence': 0.18},\n",
       "     {'color': 'blond', 'confidence': 0.07},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}}]"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# json转译\n",
    "results = response.json()\n",
    "results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### pandas 数据表格化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>faceId</th>\n",
       "      <th>faceRectangle.top</th>\n",
       "      <th>faceRectangle.left</th>\n",
       "      <th>faceRectangle.width</th>\n",
       "      <th>faceRectangle.height</th>\n",
       "      <th>faceAttributes.smile</th>\n",
       "      <th>faceAttributes.headPose.pitch</th>\n",
       "      <th>faceAttributes.headPose.roll</th>\n",
       "      <th>faceAttributes.headPose.yaw</th>\n",
       "      <th>faceAttributes.gender</th>\n",
       "      <th>...</th>\n",
       "      <th>faceAttributes.noise.value</th>\n",
       "      <th>faceAttributes.makeup.eyeMakeup</th>\n",
       "      <th>faceAttributes.makeup.lipMakeup</th>\n",
       "      <th>faceAttributes.accessories</th>\n",
       "      <th>faceAttributes.occlusion.foreheadOccluded</th>\n",
       "      <th>faceAttributes.occlusion.eyeOccluded</th>\n",
       "      <th>faceAttributes.occlusion.mouthOccluded</th>\n",
       "      <th>faceAttributes.hair.bald</th>\n",
       "      <th>faceAttributes.hair.invisible</th>\n",
       "      <th>faceAttributes.hair.hairColor</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>dc37d557-8642-48cd-ac78-5d31fe83010c</td>\n",
       "      <td>331</td>\n",
       "      <td>280</td>\n",
       "      <td>66</td>\n",
       "      <td>66</td>\n",
       "      <td>0.026</td>\n",
       "      <td>9.2</td>\n",
       "      <td>12.9</td>\n",
       "      <td>-16.3</td>\n",
       "      <td>male</td>\n",
       "      <td>...</td>\n",
       "      <td>0.08</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>[]</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>0.03</td>\n",
       "      <td>False</td>\n",
       "      <td>[{'color': 'black', 'confidence': 1.0}, {'colo...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9fbd2a78-ebde-46e7-a2c6-1aae8a79b81c</td>\n",
       "      <td>229</td>\n",
       "      <td>467</td>\n",
       "      <td>60</td>\n",
       "      <td>60</td>\n",
       "      <td>0.000</td>\n",
       "      <td>23.8</td>\n",
       "      <td>2.7</td>\n",
       "      <td>-2.8</td>\n",
       "      <td>male</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>[{'type': 'glasses', 'confidence': 0.74}]</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>0.23</td>\n",
       "      <td>False</td>\n",
       "      <td>[{'color': 'black', 'confidence': 0.99}, {'col...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>d90016e1-2a66-4671-bd0e-63961c817e87</td>\n",
       "      <td>264</td>\n",
       "      <td>873</td>\n",
       "      <td>55</td>\n",
       "      <td>55</td>\n",
       "      <td>0.000</td>\n",
       "      <td>17.1</td>\n",
       "      <td>0.2</td>\n",
       "      <td>1.8</td>\n",
       "      <td>male</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>[{'type': 'glasses', 'confidence': 0.99}, {'ty...</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>0.00</td>\n",
       "      <td>True</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>91b0e4b8-1fda-45e9-9d60-fc3538844197</td>\n",
       "      <td>418</td>\n",
       "      <td>621</td>\n",
       "      <td>51</td>\n",
       "      <td>51</td>\n",
       "      <td>0.003</td>\n",
       "      <td>6.2</td>\n",
       "      <td>1.4</td>\n",
       "      <td>-26.4</td>\n",
       "      <td>male</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>[]</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>0.05</td>\n",
       "      <td>False</td>\n",
       "      <td>[{'color': 'brown', 'confidence': 0.99}, {'col...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>a239129d-6794-4c86-b592-d2e61b1aa947</td>\n",
       "      <td>249</td>\n",
       "      <td>688</td>\n",
       "      <td>50</td>\n",
       "      <td>50</td>\n",
       "      <td>0.977</td>\n",
       "      <td>16.9</td>\n",
       "      <td>-3.7</td>\n",
       "      <td>-6.0</td>\n",
       "      <td>male</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>[{'type': 'glasses', 'confidence': 0.98}]</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>0.15</td>\n",
       "      <td>False</td>\n",
       "      <td>[{'color': 'brown', 'confidence': 0.99}, {'col...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 38 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 faceId  faceRectangle.top  \\\n",
       "0  dc37d557-8642-48cd-ac78-5d31fe83010c                331   \n",
       "1  9fbd2a78-ebde-46e7-a2c6-1aae8a79b81c                229   \n",
       "2  d90016e1-2a66-4671-bd0e-63961c817e87                264   \n",
       "3  91b0e4b8-1fda-45e9-9d60-fc3538844197                418   \n",
       "4  a239129d-6794-4c86-b592-d2e61b1aa947                249   \n",
       "\n",
       "   faceRectangle.left  faceRectangle.width  faceRectangle.height  \\\n",
       "0                 280                   66                    66   \n",
       "1                 467                   60                    60   \n",
       "2                 873                   55                    55   \n",
       "3                 621                   51                    51   \n",
       "4                 688                   50                    50   \n",
       "\n",
       "   faceAttributes.smile  faceAttributes.headPose.pitch  \\\n",
       "0                 0.026                            9.2   \n",
       "1                 0.000                           23.8   \n",
       "2                 0.000                           17.1   \n",
       "3                 0.003                            6.2   \n",
       "4                 0.977                           16.9   \n",
       "\n",
       "   faceAttributes.headPose.roll  faceAttributes.headPose.yaw  \\\n",
       "0                          12.9                        -16.3   \n",
       "1                           2.7                         -2.8   \n",
       "2                           0.2                          1.8   \n",
       "3                           1.4                        -26.4   \n",
       "4                          -3.7                         -6.0   \n",
       "\n",
       "  faceAttributes.gender  ...  faceAttributes.noise.value  \\\n",
       "0                  male  ...                        0.08   \n",
       "1                  male  ...                        0.00   \n",
       "2                  male  ...                        0.00   \n",
       "3                  male  ...                        0.00   \n",
       "4                  male  ...                        0.00   \n",
       "\n",
       "   faceAttributes.makeup.eyeMakeup  faceAttributes.makeup.lipMakeup  \\\n",
       "0                            False                             True   \n",
       "1                             True                            False   \n",
       "2                            False                            False   \n",
       "3                             True                             True   \n",
       "4                             True                             True   \n",
       "\n",
       "                          faceAttributes.accessories  \\\n",
       "0                                                 []   \n",
       "1          [{'type': 'glasses', 'confidence': 0.74}]   \n",
       "2  [{'type': 'glasses', 'confidence': 0.99}, {'ty...   \n",
       "3                                                 []   \n",
       "4          [{'type': 'glasses', 'confidence': 0.98}]   \n",
       "\n",
       "  faceAttributes.occlusion.foreheadOccluded  \\\n",
       "0                                     False   \n",
       "1                                     False   \n",
       "2                                      True   \n",
       "3                                     False   \n",
       "4                                     False   \n",
       "\n",
       "   faceAttributes.occlusion.eyeOccluded  \\\n",
       "0                                 False   \n",
       "1                                 False   \n",
       "2                                 False   \n",
       "3                                 False   \n",
       "4                                 False   \n",
       "\n",
       "   faceAttributes.occlusion.mouthOccluded  faceAttributes.hair.bald  \\\n",
       "0                                   False                      0.03   \n",
       "1                                   False                      0.23   \n",
       "2                                   False                      0.00   \n",
       "3                                   False                      0.05   \n",
       "4                                   False                      0.15   \n",
       "\n",
       "   faceAttributes.hair.invisible  \\\n",
       "0                          False   \n",
       "1                          False   \n",
       "2                           True   \n",
       "3                          False   \n",
       "4                          False   \n",
       "\n",
       "                       faceAttributes.hair.hairColor  \n",
       "0  [{'color': 'black', 'confidence': 1.0}, {'colo...  \n",
       "1  [{'color': 'black', 'confidence': 0.99}, {'col...  \n",
       "2                                                 []  \n",
       "3  [{'color': 'brown', 'confidence': 0.99}, {'col...  \n",
       "4  [{'color': 'brown', 'confidence': 0.99}, {'col...  \n",
       "\n",
       "[5 rows x 38 columns]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pandas 数据表格化\n",
    "import pandas as pd # 定义模块名字\n",
    "df_face = pd.json_normalize(results)\n",
    "df_face"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 数据取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['dc37d557-8642-48cd-ac78-5d31fe83010c',\n",
       " '9fbd2a78-ebde-46e7-a2c6-1aae8a79b81c',\n",
       " 'd90016e1-2a66-4671-bd0e-63961c817e87',\n",
       " '91b0e4b8-1fda-45e9-9d60-fc3538844197',\n",
       " 'a239129d-6794-4c86-b592-d2e61b1aa947']"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数据取值\n",
    "faceID = df_face['faceId'].values.tolist()\n",
    "faceID "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>faceId</th>\n",
       "      <th>faceAttributes.glasses</th>\n",
       "      <th>faceAttributes.emotion.neutral</th>\n",
       "      <th>faceAttributes.age</th>\n",
       "      <th>faceAttributes.gender</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>dc37d557-8642-48cd-ac78-5d31fe83010c</td>\n",
       "      <td>NoGlasses</td>\n",
       "      <td>0.085</td>\n",
       "      <td>50.0</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9fbd2a78-ebde-46e7-a2c6-1aae8a79b81c</td>\n",
       "      <td>NoGlasses</td>\n",
       "      <td>0.572</td>\n",
       "      <td>45.0</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>d90016e1-2a66-4671-bd0e-63961c817e87</td>\n",
       "      <td>ReadingGlasses</td>\n",
       "      <td>0.994</td>\n",
       "      <td>32.0</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>91b0e4b8-1fda-45e9-9d60-fc3538844197</td>\n",
       "      <td>NoGlasses</td>\n",
       "      <td>0.756</td>\n",
       "      <td>20.0</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>a239129d-6794-4c86-b592-d2e61b1aa947</td>\n",
       "      <td>ReadingGlasses</td>\n",
       "      <td>0.023</td>\n",
       "      <td>23.0</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 faceId faceAttributes.glasses  \\\n",
       "0  dc37d557-8642-48cd-ac78-5d31fe83010c              NoGlasses   \n",
       "1  9fbd2a78-ebde-46e7-a2c6-1aae8a79b81c              NoGlasses   \n",
       "2  d90016e1-2a66-4671-bd0e-63961c817e87         ReadingGlasses   \n",
       "3  91b0e4b8-1fda-45e9-9d60-fc3538844197              NoGlasses   \n",
       "4  a239129d-6794-4c86-b592-d2e61b1aa947         ReadingGlasses   \n",
       "\n",
       "   faceAttributes.emotion.neutral  faceAttributes.age faceAttributes.gender  \n",
       "0                           0.085                50.0                  male  \n",
       "1                           0.572                45.0                  male  \n",
       "2                           0.994                32.0                  male  \n",
       "3                           0.756                20.0                  male  \n",
       "4                           0.023                23.0                  male  "
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 可观察其中几组数据\n",
    "df_face[['faceId','faceAttributes.glasses','faceAttributes.emotion.neutral','faceAttributes.age','faceAttributes.gender']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Azure 认知服务-人脸演示"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### create facelist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "# 1、create  列表\n",
    "# faceListId\n",
    "faceListId =  \"hupeiqi02\"#学生填写\n",
    "create_facelists_url =  'https://facelist.cognitiveservices.azure.com/face/v1.0/facelists/{}' #学生填写\n",
    "subscription_key = 'a87c46d16dd843819033d19fd3648e6d'#学生填写\n",
    "assert subscription_key\n",
    "\n",
    "headers = {\n",
    "    # Request header\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "data = {\n",
    "# 学生填写\n",
    "            \"name\": \"artist\",\n",
    "        \"userData\": \"pohoto\",\n",
    "        \"recognitionModel\": \"recognition_03\",\n",
    "}\n",
    "\n",
    "r_create = requests.put(create_facelists_url.format(faceListId),headers=headers,json=data) #学生填写\n",
    "\n",
    "r_create"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b''"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_create.content"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### add facelist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "#先加一张脸试试\n",
    "# 2、Add face\n",
    "add_face_url = \"https://facelist.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedFaces\"#学生填写\n",
    "\n",
    "assert subscription_key\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "img_url = \"http://a1.qpic.cn/psc?/V13AubRD2hkvIo/bqQfVz5yrrGYSXMvKr.cqV.AWAUlTcOe5xVsqAtZ0OO.W4XWqF0CyyLrsVlPz9lbbeXJcuEbgLErnmy3Bp0b9kzXm4.XfwhS.4yY32Q80SQ!/b&ek=1&kp=1&pt=0&bo=VAY4BFQGOAQBKQ4!&tl=3&vuin=783639524&tm=1603533600&sce=60-2-2&rf=viewer_4\" #学生填写\n",
    "\n",
    "params_add_face={\n",
    "    \"userData\":\"李东海\"\n",
    "#学生填写\n",
    "}\n",
    "\n",
    "r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={\"url\":img_url})#学生填写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaceId': '9917056b-2bc4-4bbf-8bce-425ab719bf81'}"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_add_face.json()#返回persistedFaceId"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 封装成函数方便添加图片/函数——可以重复使用相同的功能\n",
    "\n",
    "def AddFace(img_url=str,userData=str):\n",
    "    add_face_url =\"https://facelist.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedFaces\"\n",
    "    assert subscription_key\n",
    "    headers = {\n",
    "        # Request headers\n",
    "        'Content-Type': 'application/json',\n",
    "        'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "    }\n",
    "    img_url = img_url\n",
    "    params_add_face={\n",
    "        \"userData\":userData\n",
    "    }\n",
    "    r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "    return r_add_face.status_code #返回出状态码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"http://m.qpic.cn/psc?/V13AubRD2hkvIo/bqQfVz5yrrGYSXMvKr.cqezrw7rEwaycoX38p1ppLKDcW8LLYGIkyR0bvdiNQpG.BxvhKxQ2rq4r9hb.rb90IyuPBLWp5utNgGJXqa2owDo!/b&bo=OARBBQAAAAABB1g!&rf=viewer_4\",\"宋旻浩\")\n",
    "AddFace(\"http://m.qpic.cn/psc?/V13AubRD2hkvIo/bqQfVz5yrrGYSXMvKr.cqX0*eFs3QSWv94HU9f7dkh6Lnv2tYA2SKJTkuoED.86ojpZs*bbcT7rp4SoniUTNp.E3*o3SxEDW19O0OPeHX.M!/b&bo=OARFBQAAAAABB1w!&rf=viewer_4\",\"李赫宰\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [{'persistedFaceId': '9917056b-2bc4-4bbf-8bce-425ab719bf81',\n",
       "   'userData': '李东海'},\n",
       "  {'persistedFaceId': '15386c19-f7da-45cd-aef5-3e0c42017430',\n",
       "   'userData': '宋旻浩'},\n",
       "  {'persistedFaceId': 'fda3e19a-428d-4dba-a3a3-88e8982382c0',\n",
       "   'userData': '李赫宰'}],\n",
       " 'faceListId': 'hupeiqi02',\n",
       " 'name': 'artist',\n",
       " 'userData': 'pohoto'}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 检查你的facelist的信息\n",
    "get_facelist_url = 'https://facelist.cognitiveservices.azure.com/face/v1.0/facelists/{}'#学生填写\n",
    "r_get_facelist = requests.get(get_facelist_url.format(faceListId),headers=headers,params=data)#学生填写\n",
    "r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'persistedFaceId': '9917056b-2bc4-4bbf-8bce-425ab719bf81',\n",
       "  'userData': '李东海'},\n",
       " {'persistedFaceId': '15386c19-f7da-45cd-aef5-3e0c42017430',\n",
       "  'userData': '宋旻浩'},\n",
       " {'persistedFaceId': 'fda3e19a-428d-4dba-a3a3-88e8982382c0',\n",
       "  'userData': '李赫宰'}]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "faceId =  r_get_facelist.json()['persistedFaces']\n",
    "faceId"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Find similars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': '77547feb-038b-4a4d-98b2-d58bd6bf72a3',\n",
       "  'faceRectangle': {'top': 293, 'left': 479, 'width': 231, 'height': 231},\n",
       "  'faceAttributes': {'smile': 1.0,\n",
       "   'headPose': {'pitch': -3.6, 'roll': -2.4, 'yaw': -2.2},\n",
       "   'gender': 'male',\n",
       "   'age': 25.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'ReadingGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 1.0,\n",
       "    'neutral': 0.0,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.6},\n",
       "   'noise': {'noiseLevel': 'medium', 'value': 0.57},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': True},\n",
       "   'accessories': [{'type': 'glasses', 'confidence': 0.99}],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.11,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'red', 'confidence': 0.95},\n",
       "     {'color': 'other', 'confidence': 0.94},\n",
       "     {'color': 'blond', 'confidence': 0.35},\n",
       "     {'color': 'black', 'confidence': 0.25},\n",
       "     {'color': 'gray', 'confidence': 0.14},\n",
       "     {'color': 'brown', 'confidence': 0.11},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}}]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Detect 检测人脸的id\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://facelist.cognitiveservices.azure.com/face/v1.0/detect'\n",
    "\n",
    "# 请求正文\n",
    "image_url = 'http://m.qpic.cn/psc?/V13AubRD2hkvIo/bqQfVz5yrrGYSXMvKr.cqezrw7rEwaycoX38p1ppLKDcW8LLYGIkyR0bvdiNQpG.BxvhKxQ2rq4r9hb.rb90IyuPBLWp5utNgGJXqa2owDo!/b&bo=OARBBQAAAAABB1g!&rf=viewer_4'\n",
    "\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key}\n",
    "\n",
    "# 请求参数\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 选择model\n",
    "    'recognitionModel':'recognition_03',#此参数需与facelist参数一致\n",
    "    'detectionModel':'detection_01',\n",
    "    # 可选参数,请仔细阅读API文档\n",
    "    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "# json.dumps 将json--->字符串\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "findsimilars_url = \"https://facelist.cognitiveservices.azure.com/face/v1.0/findsimilars\"\n",
    "\n",
    "# 请求正文 faceId需要先检测一张照片获取\n",
    "data_findsimilars = {\n",
    "    \"faceId\":\"77547feb-038b-4a4d-98b2-d58bd6bf72a3\",#取上方的faceID\n",
    "    \"faceListId\": \"hupeiqi02\",\n",
    "    \"maxNumOfCandidatesReturned\": 1,\n",
    "    \"mode\": \"matchFace\"#matchPerson #一种为验证模式，一种为相似值模式\n",
    "    }\n",
    "\n",
    "r_findsimilars = requests.post(findsimilars_url,headers=headers,json=data_findsimilars)\n",
    "r_findsimilars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'persistedFaceId': '15386c19-f7da-45cd-aef5-3e0c42017430',\n",
       "  'confidence': 1.0}]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_findsimilars.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>9917056b-2bc4-4bbf-8bce-425ab719bf81</td>\n",
       "      <td>李东海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>15386c19-f7da-45cd-aef5-3e0c42017430</td>\n",
       "      <td>宋旻浩</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>fda3e19a-428d-4dba-a3a3-88e8982382c0</td>\n",
       "      <td>李赫宰</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId userData\n",
       "0  9917056b-2bc4-4bbf-8bce-425ab719bf81      李东海\n",
       "1  15386c19-f7da-45cd-aef5-3e0c42017430      宋旻浩\n",
       "2  fda3e19a-428d-4dba-a3a3-88e8982382c0      李赫宰"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "#facelist里面的数据\n",
    "faceListId_df = pd.json_normalize(r_get_facelist.json()[\"persistedFaces\"])# 升级pandas才能运行\n",
    "faceListId_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>15386c19-f7da-45cd-aef5-3e0c42017430</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId  confidence\n",
       "0  15386c19-f7da-45cd-aef5-3e0c42017430         1.0"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 返回相似度的数据\n",
    "find_df = pd.json_normalize(r_findsimilars.json())# 升级pandas才能运行\n",
    "find_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>15386c19-f7da-45cd-aef5-3e0c42017430</td>\n",
       "      <td>宋旻浩</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId userData  confidence\n",
       "0  15386c19-f7da-45cd-aef5-3e0c42017430      宋旻浩         1.0"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(faceListId_df, find_df,how='inner', on='persistedFaceId').sort_values(by=\"confidence\",ascending = False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Face++ FaceSets 实践"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 准备工作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "api_secret = \"nt7xct8zCvFoUblP-ERZxya8GDsSP5No\"\n",
    "api_key = 'gjWdkKZYn0QgwYvKZWkO0fow7VxP0AAK'   # Replace with a valid Subscription Key here."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FaceSet Create（创建人脸集合）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '3d536b82f055134745368550b0def6ea',\n",
       " 'time_used': 182,\n",
       " 'face_count': 0,\n",
       " 'face_added': 0,\n",
       " 'request_id': '1603540188,4da2ea72-1fc1-4bb3-8176-fe2a750df3d1',\n",
       " 'outer_id': '00002',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1. FaceSet Create\n",
    "import requests,json\n",
    "\n",
    "display_name = \"新西游记\"\n",
    "outer_id = \"00002\"\n",
    "user_data = \"young_boy\"\n",
    "\n",
    "CreateFace_Url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/create\"\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'display_name':display_name,\n",
    "    'outer_id':outer_id,\n",
    "    'user_data':user_data\n",
    "}\n",
    "\n",
    "r = requests.post(CreateFace_Url, params=payload)\n",
    "\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FaceSet GetDetail（获取人脸集合信息）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '3d536b82f055134745368550b0def6ea',\n",
       " 'tags': '',\n",
       " 'time_used': 72,\n",
       " 'user_data': 'young_boy',\n",
       " 'display_name': '新西游记',\n",
       " 'face_tokens': [],\n",
       " 'face_count': 0,\n",
       " 'request_id': '1603540190,60f77a00-b967-4200-a50a-c68cb4977dfd',\n",
       " 'outer_id': '00002'}"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "GetDetail_Url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'outer_id':outer_id,\n",
    "}\n",
    "r = requests.post(GetDetail_Url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FaceSet AddFace（增加人脸信息）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1603540535,8afef97a-2214-4408-95b0-49cd2d9f0a7e',\n",
       " 'time_used': 1719,\n",
       " 'faces': [{'face_token': '225133ae5720e5605eecabe26c966871',\n",
       "   'face_rectangle': {'top': 337, 'left': 290, 'width': 66, 'height': 66}},\n",
       "  {'face_token': '8e6f3373449aad62018798f80f35ae03',\n",
       "   'face_rectangle': {'top': 230, 'left': 465, 'width': 65, 'height': 65}},\n",
       "  {'face_token': 'd5152c739e485fa0994db126cad335ee',\n",
       "   'face_rectangle': {'top': 267, 'left': 870, 'width': 58, 'height': 58}},\n",
       "  {'face_token': '22f46ab4eaf66d7c6f4fe3190e88fa5a',\n",
       "   'face_rectangle': {'top': 386, 'left': 1068, 'width': 56, 'height': 56}},\n",
       "  {'face_token': '928b7122521b3d1adcaa49fade756c13',\n",
       "   'face_rectangle': {'top': 422, 'left': 629, 'width': 55, 'height': 55}},\n",
       "  {'face_token': '196896c2f88830e0681be2f9abe561b9',\n",
       "   'face_rectangle': {'top': 254, 'left': 689, 'width': 50, 'height': 50}}],\n",
       " 'image_id': 'gcUed222aZC2cgRWDpmcpw==',\n",
       " 'face_num': 6}"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Detect_url=\"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "    \n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'image_url':\"http://m.qpic.cn/psc?/V13AubRD2hkvIo/bqQfVz5yrrGYSXMvKr.cqaLQFK4B0f4esItf5eIORqNv9sqrK1z67Rxdxg6SbNVXAixFK4m222f0U4oqL6eEyozfz1Pc21AWxWHXfNzIcW4!/b&bo=oAU4BKAFOAQBCS4!&rf=viewer_4\"\n",
    "}\n",
    "\n",
    "r = requests.post(Detect_url,params=payload)\n",
    "\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '3d536b82f055134745368550b0def6ea',\n",
       " 'time_used': 679,\n",
       " 'face_count': 1,\n",
       " 'face_added': 1,\n",
       " 'request_id': '1603540911,efd6974c-d350-4165-bcd9-b76ac2879ac5',\n",
       " 'outer_id': '00002',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace_url = \" https://api-cn.faceplusplus.com/facepp/v3/faceset/addface\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'3d536b82f055134745368550b0def6ea',\n",
    "    'face_tokens':'225133ae5720e5605eecabe26c966871',\n",
    "}\n",
    "\n",
    "r = requests.post(AddFace_url,params=payload,json={\"url\":img_url})\n",
    "\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FaceSet RemoveFace（移除人脸信息）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '3d536b82f055134745368550b0def6ea',\n",
       " 'face_removed': 1,\n",
       " 'time_used': 166,\n",
       " 'face_count': 0,\n",
       " 'request_id': '1603541338,ebff7dfc-4f4d-4119-b37f-50b73375f42a',\n",
       " 'outer_id': '00002',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "RemoveFace_url = \" https://api-cn.faceplusplus.com/facepp/v3/faceset/removeface\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'3d536b82f055134745368550b0def6ea',\n",
    "    'face_tokens':'225133ae5720e5605eecabe26c966871',\n",
    "}\n",
    "\n",
    "r = requests.post(RemoveFace_url,params=payload)\n",
    "\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FaceSet Update（更新人脸集合信息）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '3d536b82f055134745368550b0def6ea',\n",
       " 'request_id': '1603541417,204ed95c-d25b-4015-ac16-b1af7df95d42',\n",
       " 'time_used': 58,\n",
       " 'outer_id': '00002'}"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Update_url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/update\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'3d536b82f055134745368550b0def6ea',\n",
    "    'user_data':\"young_boy\",\n",
    "}\n",
    "\n",
    "r = requests.post(Update_url,params=payload)\n",
    "\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Compare Face（对比人脸相似度）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [],
   "source": [
    "songminhao1 = \"http://m.qpic.cn/psc?/V13AubRD2hkvIo/bqQfVz5yrrGYSXMvKr.cqaDmm2JA0Ximzwj4R1S9*6e0tx6KefO.9BWvddxQlUKC0MPOHFrIKRwxUhGtKPcsscnBEo4Yj*1M4e*hZHkR4ik!/b&bo=7gIyAu4CMgIBCS4!&rf=viewer_4\"\n",
    "songminhao2 = \"http://m.qpic.cn/psc?/V13AubRD2hkvIo/TmEUgtj9EK6.7V8ajmQrELJrSxwREXEsw7GY4aLva6IkzDYmX8m.skmpfe30sE1xwXA6BWiCiJQjovPLpRg*Ev0F3UR5vA9X0.qwcswHxao!/b&bo=OARBBQAAAAABF0g!&rf=viewer_4\"\n",
    "biaozhixun  = \"http://m.qpic.cn/psc?/V13AubRD2hkvIo/bqQfVz5yrrGYSXMvKr.cqS9X0QAFwfxr5QHB6Yuv5iyATt1TqWO6wPO4eyVdpXTtt1*yt7WP.3iaJvGFuZumdMrNspNvkH0xYaiowwbYeck!/b&bo=OARGBTgERgUBCS4!&rf=viewer_4\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 方案1:直接对比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faces1': [{'face_rectangle': {'width': 148,\n",
       "    'top': 126,\n",
       "    'left': 350,\n",
       "    'height': 148},\n",
       "   'face_token': 'f9de2e2a2045d622215683757cfabede'}],\n",
       " 'faces2': [{'face_rectangle': {'width': 236,\n",
       "    'top': 316,\n",
       "    'left': 479,\n",
       "    'height': 236},\n",
       "   'face_token': '53a26d3fc572ab1d06c796b8646f0343'}],\n",
       " 'time_used': 1181,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-5': 73.975, '1e-4': 69.101},\n",
       " 'confidence': 75.521,\n",
       " 'image_id2': 'VNZ2TccNcOzFdAADv2ygRg==',\n",
       " 'image_id1': '3FgEqnLnIBybuYNKskMsVQ==',\n",
       " 'request_id': '1603542703,0403595b-abd3-4339-8981-d508c391fa2a'}"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Compare_url = \"https://api-cn.faceplusplus.com/facepp/v3/compare\"\n",
    "\n",
    "payload ={\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'image_url1':songminhao1,\n",
    "    'image_url2':songminhao2\n",
    "}\n",
    "\n",
    "r = requests.post(Compare_url,params=payload)\n",
    "\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 方案2:与人脸集合进行对比"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 面部检测(获取face_token)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1603542814,041a66d0-8767-4032-bca4-bc965abe523f',\n",
       " 'time_used': 297,\n",
       " 'faces': [{'face_token': '2ce57ae603ccf9bb7ceeb547acd26aac',\n",
       "   'face_rectangle': {'top': 126, 'left': 350, 'width': 148, 'height': 148},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 24},\n",
       "    'smile': {'value': 100.0, 'threshold': 50.0},\n",
       "    'emotion': {'anger': 0.0,\n",
       "     'disgust': 0.009,\n",
       "     'fear': 0.0,\n",
       "     'happiness': 99.99,\n",
       "     'neutral': 0.0,\n",
       "     'sadness': 0.0,\n",
       "     'surprise': 0.0}}}],\n",
       " 'image_id': '3FgEqnLnIBybuYNKskMsVQ==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Detect_url = 'https://api-cn.faceplusplus.com/facepp/v3/detect' \n",
    "img_url = songminhao1\n",
    "\n",
    "payload = {\n",
    "    \"image_url\":img_url,\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'return_attributes':'gender,age,smiling,emotion', \n",
    "}\n",
    "\n",
    "r = requests.post(Detect_url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 加入人脸集合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '3d536b82f055134745368550b0def6ea',\n",
       " 'time_used': 550,\n",
       " 'face_count': 1,\n",
       " 'face_added': 1,\n",
       " 'request_id': '1603542955,558d30e0-06d2-4f00-94a4-aa58984ad641',\n",
       " 'outer_id': '00002',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace_url = \" https://api-cn.faceplusplus.com/facepp/v3/faceset/addface\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'3d536b82f055134745368550b0def6ea',\n",
    "    'face_tokens':'225133ae5720e5605eecabe26c966871',\n",
    "}\n",
    "\n",
    "r = requests.post(AddFace_url,params=payload,json={\"url\":img_url})\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
